import Vue from 'vue'
import Vuex from 'vuex'
import state from './state.js'
import actions from './actions.js'
import mutations from './mutations.js'

Vue.use(Vuex)

// 自动化部署子模块
const modules = {}
const moduleContext = require.context('./modules', false, /\.js$/)

moduleContext.keys().forEach((fileName, index, arr) => {
  const moduleName = arr[index].slice(2, -3)
  const moduleConfig = moduleContext(fileName).default
  modules[moduleName] = moduleConfig
})

export default new Vuex.Store({
  state,
  mutations,
  actions,
  modules
})
